package com.yl.ifanr;

import com.yl.ifanr.R;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageButton;
import android.widget.TextView;
import android.content.Intent;
import android.util.Log;
import android.view.*;
import android.text.Html;
import android.text.Html.ImageGetter;
import android.graphics.drawable.Drawable;
import java.net.URL;
import com.yl.util.Constants;

public class ActivityShowDesc extends Activity {
	public final String TAG = "details";
	
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		setContentView(R.layout.showdescription);
		String content = null;
		Intent startingIntent = getIntent();

		if (startingIntent != null) {
			String title = startingIntent.getStringExtra("title");
			String desc = startingIntent.getStringExtra("desc");
			String acontent = startingIntent.getStringExtra("content");
			String link = startingIntent.getStringExtra("link");
			String pubdate = startingIntent.getStringExtra("pubdate");
//			Log.d(TAG, acontent);
			
			content = title+"\n\n" + pubdate+ "\n\n"
			+ acontent + "\n\n"
			+ "\n\n详细信息请访问以下网址:\n" + link + "\n\n";
			
		} else {
			content = "不好意思程序出错了。";
		}

		TextView textView = (TextView) findViewById(R.id.content);
		textView.setText(Html.fromHtml(content,imgGetter,null));

		ImageButton backbutton = (ImageButton) findViewById(R.id.back);

		backbutton.setOnClickListener(new ImageButton.OnClickListener() {
			public void onClick(View v) {
				finish();
			}
		});
	}
	
	ImageGetter imgGetter = new Html.ImageGetter() {
		public Drawable getDrawable(String source) {
		Drawable drawable = null;
		int picWidth = 0,picHeight = 0;
		Log.d("Image Path", source);
		URL url;
		try {
			url = new URL(source);
			drawable = Drawable.createFromStream(url.openStream(), "");
		} catch (Exception e) {
			return null;
		}
		int intrimsicWidth = drawable.getIntrinsicWidth();
		int intrinsicHeight = drawable.getIntrinsicHeight();
		if(intrimsicWidth>Constants.SCREEN_WIDTH){
			picWidth = Constants.SCREEN_WIDTH;
			picHeight = picWidth*intrinsicHeight/intrimsicWidth;
		}else{
			picWidth = intrimsicWidth;
			picHeight = intrinsicHeight;
		}
		drawable.setBounds(0, 0, picWidth, picHeight);
		return drawable;
		}
	};

}